package org.example.producer;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.example.constant.Constants;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConfirmProducer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //建立连接
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("123.57.1.114");
        factory.setPort(5672);
        factory.setVirtualHost("test");
        factory.setUsername("admin");
        factory.setPassword("admin");

        Connection connection = factory.newConnection();
        //开启信道
        Channel channel = connection.createChannel();
        //声明队列
        channel.queueDeclare(Constants.CONFIRM_QUEUE,true,false,false,null);
        //发送消息
        String msg = "rabbitmq confirm";
        channel.basicPublish("",Constants.CONFIRM_QUEUE,null,msg.getBytes());
        System.out.println("消息发送成功");
        channel.close();
        connection.close();
    }
}
